package com.testdemo.web.shapejudge.impl;
 
public class TriangleJudgeQuestionImpl extends ShapeJudgeQuestionImpl {

	int BorderA;
	int BorderB;
	int BorderC;

	public TriangleJudgeQuestionImpl() {
		BorderA = Math.abs((int) (Math.random() * 100 + 1));
		BorderB = Math.abs((int) (Math.random() * 100 + 1));
		BorderC = Math.abs((int) (Math.random() * 100 + 1));
		RightAnswer = Judge();
	}

	public TriangleJudgeQuestionImpl(int a, int b, int c) {
		BorderA = a;
		BorderB = b;
		BorderC = c;
		RightAnswer =Judge();
	}

	public boolean Judge() {
		if (((BorderB + BorderC) > BorderA) && ((BorderA + BorderC) > BorderB)
				&& ((BorderB + BorderA) > BorderC))
			return true;
		else
			return false;
	}

	@Override
	public String getQusitionString() {
		// TODO Auto-generated method stub
		String temp;
		temp = "题目：三条边，边A为 " + Integer.toString(BorderA) +
				"，边B为 " + Integer.toString(BorderB) +
				"，边C为 " + Integer.toString(BorderC) +
				", 请判定这三条边是否能构成三角形。";
		return temp;		 
	}

	@Override
	public String getRightAnswerString() {
		// TODO Auto-generated method stub
		String temp;
		temp = "正确答辩：三条边，边A为 " + Integer.toString(BorderA) +
				"，边B为 " + Integer.toString(BorderB) +
				"，边C为 " + Integer.toString(BorderC);
		if (this.RightAnswer == true)
			temp +=	",  三条边能构成三角形。";
		else
			temp +=	",  三条边不能构成三角形。";
		return temp;
	}

	@Override
	public String getAnsewerString() {
		// TODO Auto-generated method stub
		String temp;
		temp = "你的答辩：三条边，边A为 " + Integer.toString(BorderA) +
				"，边B为 " + Integer.toString(BorderB) +
				"，边C为 " + Integer.toString(BorderC);
		if (this.Answer == true)
		{
			temp +=	",  三条边能构成三角形。";
		}
			
		else
		{
			temp +=	",  三条边不能构成三角形。";
		}
		return temp;
	}

	public enum TriangleType {
		NotTriangle, Equilateral, Scalene, Isosceles
	}

	public TriangleType JudgeType() {
		if (!this.Judge())
			return TriangleType.NotTriangle;
		else {
			if ((BorderA == BorderB) && (BorderB == BorderC))
				return TriangleType.Equilateral;
			else if ((BorderA != BorderB) && (BorderB != BorderC)
					&& (BorderC != BorderA))
				return TriangleType.Scalene;
			else
				return TriangleType.Isosceles;
		}

	}
}
